package cn.tedu.controller;

import cn.tedu.controller.BaseAndEx.BaseController;
import cn.tedu.entity.Area;
import cn.tedu.entity.City;
import cn.tedu.entity.Province;
import cn.tedu.service.port.DistrictService;
import cn.tedu.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;


@Controller
@RequestMapping("/dict")
public class DictController extends BaseController {

    @Resource
    private DistrictService districtService;

    /**
     * 获取省列表
     * @return 返回省集合
     */
    @ResponseBody
    @RequestMapping("/provinces.do")
    public JsonResult getProvinces(){
        List<Province> provinces = districtService.getProvince();
        return new JsonResult(provinces);
    }

    /**
     * 获取市列表
     * @param provinceCode  省代号
     * @return  返回市列表集合
     */
    @ResponseBody
    @RequestMapping("/cities.do")
    public JsonResult getCities(String provinceCode){
        List<City> cities = districtService.getCity(provinceCode);
//        System.out.println("获取市:"+provinceCode);
//        System.out.println(cities);
        return new JsonResult(cities);
    }

    /**
     * 获取区列表
     * @param cityCode  市代号
     * @return  返回区列表集合
     */
    @ResponseBody
    @RequestMapping("/area.do")
    public JsonResult getArea(String cityCode){
        List<Area> areas = districtService.getArea(cityCode);
        return new JsonResult(areas);
    }
}
